﻿package  
{
	import flash.display.Sprite;
	import com.bit101.components.Panel;
	import com.bit101.components.PushButton;
	import flash.display.LoaderInfo;
	import flash.events.MouseEvent;
	import flash.system.System;
	
	/**
	 * Customizable button to copy text to clipboard
	 * @author François Desroches
	 */
	public class Clipboard extends Sprite
	{
		private var text:String = '';
		
		public function Clipboard() 
		{
			var pushButton:PushButton = new PushButton(this, 0, 0, 'Copy to clipboard', copy);
			pushButton.width = stage.stageWidth;
			pushButton.height = stage.stageHeight;
			
			var paramObj:Object = LoaderInfo(this.loaderInfo).parameters;
			if (paramObj['text'])
			{
				text = String(paramObj['text']);
			}
		}
		
		public function copy(event:MouseEvent):void
		{
			System.setClipboard(text);
		}
	}
}